package net.lab1024.sa.base.module.support.cmdb.controller;

import net.lab1024.sa.base.common.domain.ValidateList;

import net.lab1024.sa.base.module.support.cmdb.domain.form.CmdbAddForm;
import net.lab1024.sa.base.module.support.cmdb.domain.form.CmdbQueryForm;
import net.lab1024.sa.base.module.support.cmdb.domain.form.CmdbUpdateForm;
import net.lab1024.sa.base.module.support.cmdb.domain.vo.CmdbVO;
import net.lab1024.sa.base.module.support.cmdb.service.CmdbService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * chenyuqiang Controller
 *
 * @Author chenyuqiang
 * @Date 2025-10-16 19:03:13
 * @Copyright 1
 */

@RestController
@Tag(name = "chenyuqiang")
public class CmdbController {

    @Resource
    private CmdbService cmdbService;

    @Operation(summary = "分页查询 @author chenyuqiang")
    @PostMapping("/cmdb/queryPage")
    @SaCheckPermission("cmdb:query")
    public ResponseDTO<PageResult<CmdbVO>> queryPage(@RequestBody @Valid CmdbQueryForm queryForm) {
        return ResponseDTO.ok(cmdbService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author chenyuqiang")
    @PostMapping("/cmdb/add")
    @SaCheckPermission("cmdb:add")
    public ResponseDTO<String> add(@RequestBody @Valid CmdbAddForm addForm) {
        return cmdbService.add(addForm);
    }

    @Operation(summary = "更新 @author chenyuqiang")
    @PostMapping("/cmdb/update")
    @SaCheckPermission("cmdb:update")
    public ResponseDTO<String> update(@RequestBody @Valid CmdbUpdateForm updateForm) {
        return cmdbService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author chenyuqiang")
    @PostMapping("/cmdb/batchDelete")
    @SaCheckPermission("cmdb:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Integer> idList) {
        return cmdbService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author chenyuqiang")
    @GetMapping("/cmdb/delete/{id}")
    @SaCheckPermission("cmdb:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Integer id) {
        return cmdbService.delete(id);
    }
}
